package com.paper.tiger.easy.rpc.s.client.client;

import com.paper.tiger.easy.rpc.s.client.common.Dove;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author ZouHaiBo
 * @version 1.0, 2021/6/17 20:08
 * @since JDK 1.8
 */
public class SyncUtil {

    private static Map<String, ArrayBlockingQueue<Dove>> data = new HashMap<>();


    public static Dove getData(String doveId) throws InterruptedException {
        return data.get(doveId).take();
    }


    public static void putData(String doveId, Dove obj) throws InterruptedException {
        if (obj == null) {
            data.get(doveId).put(obj);
        } else {
            data.get(doveId).put(obj);
        }
    }


    public static void addDove(String doveId) {
        data.put(doveId, new ArrayBlockingQueue<Dove>(1));
    }
}
